package com.guiwu.gteway.industryapp.Device.module;

import android.os.Parcel;
import android.os.Parcelable;

import com.google.gson.annotations.SerializedName;

import java.io.Serializable;

/**
 * Created by 乔冠 on 2017/12/26. 网关的数据抽象
 */

public class GateWay implements Parcelable {

    private String sn;
    @SerializedName("deviceId")
    private String GateWayId;

    private String apiKey;
    @SerializedName("title")
    private String GateWayName;

    @SerializedName("location")
    private GateWayLocation location; //jsonString

    @SerializedName("auth")
    private int competence; //权限

    private int isOnline = -1;  //0离线  ，1在线

    private String fromGroup;

    private String connectType;//联网类型

    private int shareCompetence;//分享者的权限等级

    private String shareName;//分享者的用户名

    //反序列化
    protected GateWay(Parcel in) {
        sn = in.readString();
        GateWayId = in.readString();
        apiKey = in.readString();
        GateWayName = in.readString();
        competence = in.readInt();
        location = in.readParcelable(GateWayLocation.class.getClassLoader());
        isOnline = in.readInt();
        fromGroup = in.readString();
        connectType = in.readString();
        shareCompetence = in.readInt();
        shareName = in.readString();
    }

    public static final Creator<GateWay> CREATOR = new Creator<GateWay>() {
        @Override
        public GateWay createFromParcel(Parcel in) {
            return new GateWay(in);
        }

        @Override
        public GateWay[] newArray(int size) {
            return new GateWay[size];
        }
    };


    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public String getGateWayId() {
        return GateWayId;
    }

    public void setGateWayId(String gateWayId) {
        GateWayId = gateWayId;
    }

    public String getApiKey() {
        return apiKey;
    }

    public void setApiKey(String apiKey) {
        this.apiKey = apiKey;
    }

    public String getGateWayName() {
        return GateWayName;
    }

    public void setGateWayName(String gateWayName) {
        GateWayName = gateWayName;
    }

    public GateWayLocation getGateWayLocation() {
        return location;
    }

    public void setGateWayLocation(GateWayLocation gateWayLocation) {
        location = gateWayLocation;
    }

    public int getCompetence() {
        return competence;
    }

    public void setCompetence(int competence) {
        this.competence = competence;
    }

    public int getIsOnline() {
        return isOnline;
    }

    public void setIsOnline(int isOnline) {
        this.isOnline = isOnline;
    }

    public String getFromGroup() {
        return fromGroup;
    }

    public void setFromGroup(String fromGroup) {
        this.fromGroup = fromGroup;
    }

    public synchronized String getConnectType() {
        return connectType;
    }

    public synchronized void setConnectType(String connectType) {
        this.connectType = connectType;
    }

    public synchronized String getShareName() {
        return shareName;
    }

    public synchronized void setShareName(String shareName) {
        this.shareName = shareName;
    }

    @Override
    public String toString() {
        return GateWayName + "  状态" + isOnline + "   id" + getGateWayId() +  "   权限：" + competence + "   位置" + location;
    }


    //序列化
    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(sn);
        dest.writeString(GateWayId);
        dest.writeString(apiKey);
        dest.writeString(GateWayName);
        dest.writeInt(competence);
        dest.writeParcelable(location,flags);
        dest.writeInt(isOnline);
        dest.writeString(fromGroup);
        dest.writeString(connectType);
        dest.writeInt(shareCompetence);
        dest.writeString(shareName);
    }


}
